package learn_design_patterns.c2.weather;

import java.util.Observable;
import java.util.Observer;

public class HeatIndexDisplay implements Observer, DisplayElement {

	private float temp;
	private Observable weatherData;

	public HeatIndexDisplay(WeatherData weatherData) {
		this.weatherData = weatherData;
		this.weatherData.addObserver(this);
	}

	@Override
	public void display() {
		System.out.println("Heat index is " + temp + "F");
	}

	// @Override
	// public void update(float temp, float humidity, float pressure) {
	// this.temp = temp;
	// display();
	// }

	@Override
	public void update(Observable o, Object arg) {
		if (o instanceof WeatherData) {
			WeatherData weatherData = (WeatherData) o;
			this.temp = weatherData.getTemperature();
			display();
		}
	}

}
